{% extends 'dashboard/base.html' %}

{% block body %}

        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-body">
                        <br>
                        <div class="d-md-flex align-items-center">
                            <h5 class="card-title">Cookies Sessions List</h5>
                        </div>
                        <br>
                        <div class="row">
                            <div class="table-responsive">
                                <table id="cookies_list" class="table table-bordered data-table">
                            <thead>
                            <tr>
                                <th><p><label><input type="checkbox" id="checkAll"/></label></p></th>
                                <th>URL</th>
                                <th>Cookies</th>
                                <th>Action</th>
                            </tr>
                            </thead>
                            <tbody>{% for data in all_cookies %}
                            <tr data-target="#">
                                <td>
                                    <form>
                                        <label><input type="checkbox" value="{{data.url}}" name="del_scan_id"
                                                      onClick="reload">

                                        </label>
                                    </form>
                                </td>
                                <td>{{ data.url }}
                                </td>
                                <td>
                                    {{ data.cookie }}
                                </td>
                                <td>
                                    <form action="{% url 'webscanners:cookies_del' %}" method="post" class="forms-sample">

                                        {% csrf_token %}
                                        <input type="hidden" name="url" value="{{data.url}}"/>
                                        <button class="btn btn-danger btn-sm"><i class="fas fa-times"></i>
                                                </button>
                                    </form>
                                </td>
                            </tr>
                            {% endfor %}
                            </tbody>
                        </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>


<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">

    $("#checkAll").change(function () {
        $("input:checkbox").prop('checked', $(this).prop("checked"));
    });
    $(document).ready(function() {
        $("button").click(function(){
            var scan_id = ['a7af5b68-b661-45ad-90fd-ffa27526cdce'];
            $.each($("input[name='del_scan_id']:checked"), function(){
                scan_id.push($(this).val());
            });

            var json_scanid = scan_id.join(", ");
            $.ajax({
                type:'POST',
                <!--contentType: 'application/json; charset=utf-8',-->
                url:'{% url 'webscanners:cookies_del' %}',
                data:{
                   url: json_scanid,
                   csrfmiddlewaretoken:$('input[name=csrfmiddlewaretoken]').val()
                },
                sucess:function(){

                }
            });
            setTimeout(function(){location.reload();},1000);
        });

    });


</script>

{% endblock %}